﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

using Styx.Helpers;

namespace natfothPlugins
{
    public partial class HelperForm : Form
    {
        public static HelperForm Instance { get; private set; }
        public static bool IsValid { get { return Instance != null && Instance.Visible && !Instance.Disposing && !Instance.IsDisposed; } }

        public HelperForm()
        {
            InitializeComponent();
            Instance = this;
        }
        private void detectPlayersCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            NAssist.MySettings.DetectPlayers = detectPlayersCheckbox.Checked;
            NAssist.Instance.DetectPlayers = detectPlayersCheckbox.Checked;
        }

        private void minTeleportDistanceText_TextChanged(object sender, EventArgs e)
        {
            int teleportDistance;

            int.TryParse(minTeleportDistanceText.Text, out teleportDistance);

            if (teleportDistance < 20)
            {
                teleportDistance = 20;
            }

            NAssist.MySettings.MinTeleportDist = teleportDistance;

            NAssist.Instance.TeleportDistance = teleportDistance;
        }

        private void useTeleportCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            minTeleportDistanceText.Enabled = useTeleportCheckbox.Checked;

            NAssist.MySettings.UseTeleport = useTeleportCheckbox.Checked;

            NAssist.Instance.UseTeleport = useTeleportCheckbox.Checked;
        }
        private void noCollisionLiteMountedCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            NAssist.MySettings.NoCollisionLiteMounted = noCollisionLiteMountedCheckbox.Checked;
            NAssist.Instance.UseCollisionLightMount = noCollisionLiteMountedCheckbox.Checked;
            noCollisionAllCheckbox.Enabled = noCollisionLiteMountedCheckbox.Checked;

        }

        private void noCollisionAllCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            NAssist.MySettings.NoCollisionLiteAll = noCollisionAllCheckbox.Checked;
            NAssist.Instance.UseCollisionAll = noCollisionAllCheckbox.Checked;
        }

        private void usingABCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            NAssist.MySettings.UseAB = usingABCheckBox.Checked;
            NAssist.Instance.UsingAB = usingABCheckBox.Checked;
        }

        private void HelperForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            NAssist.MySettings.Save();
        }

        private void HelperForm_Load(object sender, EventArgs e)
        {
            detectPlayersCheckbox.Checked = NAssist.Instance.DetectPlayers;
            minTeleportDistanceText.Text = Convert.ToString(NAssist.Instance.TeleportDistance);
            useTeleportCheckbox.Checked = NAssist.Instance.UseTeleport;
            noCollisionLiteMountedCheckbox.Checked = NAssist.Instance.UseCollisionLightMount;
            noCollisionAllCheckbox.Checked = NAssist.Instance.UseCollisionAll;
            usingABCheckBox.Checked = NAssist.Instance.UsingAB;
            waterWalkingCheckBox.Checked = NAssist.Instance.UseWaterHack;
            climbHackCheckBox.Checked = NAssist.Instance.UseClimbHack;

            noCollisionAllCheckbox.Enabled = noCollisionLiteMountedCheckbox.Checked;
        }

        private void climbHackCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            NAssist.MySettings.UseClimbHack = climbHackCheckBox.Checked;
            NAssist.Instance.UseClimbHack = climbHackCheckBox.Checked;
        }

        private void waterWalkingCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            NAssist.MySettings.UseWaterHack = waterWalkingCheckBox.Checked;
            NAssist.Instance.UseWaterHack = waterWalkingCheckBox.Checked;
        }
    }
}